package com.SouthernWall_404.AgeDust.mixin;

import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(EntityRenderer.class)
public abstract class PlayerRendererMixin<T extends Entity> {

    @Redirect(
            method = "renderNameTag",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/entity/Entity;getDisplayName()Lnet/minecraft/network/chat/Component;"
            )
    )
    private Component redirectNameTag(Entity entity) {
        if (entity instanceof Player player) {
            // 优先使用自定义名称
            if (player.getCustomName() != null) {
                return player.getCustomName();
            }
        }
        return entity.getDisplayName();
    }
}